# 角谷猜想
def guess(number):
    i = 0
    original_number = number 
    while number != 1:
        if number % 2 == 0:
            number = number / 2
        else:
            number = number * 3 + 1
        i += 1
    print(f"{original_number}经过{i}次变化后回到1")
num = int(input("请输入一个大于1的正整数:"))
guess(num)

# 饮品自动售货机

# 饮品信息
def all_goods():
    goods = {"可口可乐":2.5,"百事可乐":2.5,"冰红茶":3,"脉动":3.5,
            "果缤纷":3,"绿茶":3,"茉莉花茶":3,"尖叫":2.5}
    return goods
# 展示饮品信息
def show_goods():
    for x , y in all_goods().items():
        print(x,":",str(y) + "元")
# 计算总额
def total(goods_dict):
    count = 0
    for name , num in goods_dict.items():
        total_money = all_goods()[name] * num
        # 总金额
        count  += total_money
    print("需要支付的金额:",count,"元")
def main():
    goods_dict = {}
    print("饮   品  自  动  售  货  机")
    show_goods()
    #循环选购的商品
    print("输入q完成购买")
    while True:
        goods_name = input("请输入购物的商品:")
        if goods_name == 'q':
            break
        if  goods_name in [goods_name for g_name in all_goods().keys()]:
            goods_num = input("请输入购物数量:")
            if goods_num.isdigit():
                goods_dict[goods_name] = float(goods_num)
            else:
                print('商品数量不合法')
        else:
            print('请输入正确的商品名称')
    total(goods_dict)
if __name__ == '__main__':
    main()
# 兔子数列
def fibonacci(month):
    if month == 0 or month == 1:
        return 1
    else:
        return fibonacci(month-1) + fibonacci(month-2)
# 测试经过12个月份后兔子的对数
result = fibonacci(12)
print(result)

# 归并排序
def merge_sort(li):
    n = len(li)
    if n == 1:
        return li
    # 把数据分成左右两部分
    mid = n // 2
    left = li[:mid]
    right = li[mid:]
    # 递归拆分
    left_res = merge_sort(left)
    right_res = merge_sort(right)
    # 把下层返回上来的数据，组成有序序列
    result = merge(left_res,right_res)
    # 合并
    return result
def merge(left,right):
    result = []
    left_index = 0
    right_index = 0
    while left_index < len(left) and right_index < len(right):
        if left[left_index] <= right[right_index]:
            result.append(left[left_index])
            left_index +=1
        else:
            result.append(right[right_index])
            right_index += 1 
    # while循环结束后，把剩下的数据添加进来
    result += right[right_index:]
    result += left[left_index:]
    return result
if __name__ == '__main__':
    list_demo = [6,5,7,4,3,1]
    print(merge_sort(list_demo))
